#include<stdio.h>
#include<sqlite3.h> 
#include<string.h>
#include <stdlib.h>
//typedef int(*Sqlite_cb)(void *para,int columnCount,char **columnValue,char**columnName);
int Sqlite_cb(void *para,int columnCount,char **columnValue,char**columnName)
{
    printf("columnCount=%d\n",columnCount);
    for(int i=0;i<columnCount;i++)
    {
        printf("%s:%s|",columnName[i],columnValue[i]);
    }
    printf("\n");
    return 0;
}
int main(int argc,char **argv)
{
    int id;
    int age;

    char name[20];

    char sql[1024]={0};
    char*errmsg;

    if(argc!=2)
    {
        printf("please input db name\n");
        return 1;
    }
    sqlite3 * db;
    int ret=sqlite3_open(argv[1],&db);

    if(ret!=SQLITE_OK)
    {
        printf("sqlite3_open error%s",sqlite3_errmsg(db));
        return 1;
    }
    printf("sqlite open db successful!\n");
    strcpy(sql,"create table IF NOT EXISTS student(id integer primary key,name text,age integer);");
    ret= sqlite3_exec(db,sql,nullptr,nullptr,&errmsg);
    if(ret!=SQLITE_OK)
    {
        printf("exec error:%s\n",sqlite3_errmsg(db));
    }
  
    memset(sql,0,strlen(sql));
    strcpy(sql,"select * from student");
    ret= sqlite3_exec(db,sql,Sqlite_cb,nullptr,&errmsg);
    if(ret!=SQLITE_OK)
    {
        printf("select error:%s\n",sqlite3_errmsg(db));
    }
    sqlite3_close(db);
    return 0;
}